import pyautogui
pyautogui.position()

from PIL import ImageGrab
from ctypes import *
import time


# LOL已经屏蔽模拟键鼠点击 所以需要使用驱动级的键鼠操作
dd_dll = windll.LoadLibrary(r'D:\master-master\master-master\Drivers\Drivers\1.Simple\DD94687.64.dll')
time.sleep(2)
st = dd_dll.DD_btn(0)
if st==1:
    print("OK")
else:
    print("Error")
    exit(101)
while True:
    time.sleep(1)
    px = ImageGrab.grab().load()
    m = px[884, 776]
    #开始
    if m[0]+m[1]+m[2] == 311:
        print("Mouse move abs.")
        dd_dll.DD_mov(884, 776)
        time.sleep(1)
        dd_dll.DD_btn(1)
        dd_dll.DD_btn(2)
    #对局确认
    m1 = px[963, 677]
    print(m1[0]+m1[1]+m1[2])
    if m1[0]+m1[1]+m1[2] == 524:
        dd_dll.DD_mov(963, 677)
        time.sleep(1)
        dd_dll.DD_btn(1)
        dd_dll.DD_btn(2)
    # 拿牌
    m2 = px[664, 1013]
    if m2[0]+m2[1]+m2[2] == 480:
        dd_dll.DD_mov(664, 1013)
        time.sleep(1)
        dd_dll.DD_btn(1)
        time.sleep(1)
        dd_dll.DD_btn(2)
        time.sleep(2)
    #结束
    m3 = px[813, 544]
    if m3[0]+m3[1]+m3[2] == 540:
        dd_dll.DD_mov(813, 544)
        time.sleep(1)
        dd_dll.DD_btn(1)
        time.sleep(1)
        dd_dll.DD_btn(2)
        time.sleep(2)
    #再来一局
    m4 = px[847, 778]
    if m4[0]+m4[1]+m4[2] == 105:
        dd_dll.DD_mov(847, 778)
        time.sleep(1)
        dd_dll.DD_btn(1)
        time.sleep(1)
        dd_dll.DD_btn(2)
        dd_dll.DD_mov(647, 778)

    m5 = px[463, 915]

    if m5[0]+m5[1]+m5[2] == 463:
        dd_dll.DD_mov(463, 915)
        time.sleep(1)
        dd_dll.DD_btn(1)
        time.sleep(1)
        dd_dll.DD_btn(2)
        time.sleep(1)
        dd_dll.DD_btn(1)
        time.sleep(1)
        dd_dll.DD_btn(2)



